<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_left">
          <div>{{ i18n('business.inquiry.view') }}</div>
        </div>

        <div class="admin_main_block_right">
          <div>
            <el-button icon="Back" @click="router.go(-1)">
              {{ i18n('common.return') }}
            </el-button>
          </div>
        </div>
      </div>

      <div class="admin_form_main">
        <el-form label-width="120px" ref="formRef" :model="dataForm" :rules="dataRule">
          <el-card class="box-card" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('common.basic_info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-descriptions border :column="3">
                <el-descriptions-item width="200" :label="i18n('business.inquiry.order_no')" label-align="right">
                  {{ dataForm.order_no }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.create_time')" label-align="right" :span="2">
                  {{ dataForm.create_time }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.nickname')" label-align="right">
                  <el-text v-if="dataForm.member">
                    {{ dataForm.member.chinese_nickname }}
                  </el-text>
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.mobile')" label-align="right" :span="2">
                  <el-text v-if="dataForm.member">
                    {{ dataForm.member.username }}
                  </el-text>
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.load_time')" label-align="right">
                  <el-text v-if="dataForm.start_time">
                    {{ dataForm.start_time }} ~ {{ dataForm.end_time }}
                  </el-text>
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.valid_hour')" label-align="right">
                  {{ dataForm.valid_hour }} {{ $t('common.hour') }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.valid_time')" label-align="right">
                  {{ dataForm.valid_time }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.description')" label-align="right" :span="3">
                  {{ dataForm.description }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.remark')" label-align="right" :span="3">
                  {{ dataForm.remark }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.inquiry_status')" label-align="right">
                  <el-text tag="b" :type="dataForm.inquiry_status.value == 0 ? 'info' : ((dataForm.inquiry_status.value == 1 || dataForm.inquiry_status.value == 4 || dataForm.inquiry_status.value == 5 || dataForm.inquiry_status.value == 6) ? 'primary' : (dataForm.inquiry_status.value == 3 ? 'success' : 'danger'))">
                    {{ dataForm.inquiry_status.text }}
                  </el-text>
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.view_total')" label-align="right">
                  {{ dataForm.view_total }} {{ $t('business.inquiry.part') }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.offer_total')" label-align="right">
                  {{ dataForm.offer_total }} {{ $t('business.inquiry.part') }}
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('business.inquiry.harbor.info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-table :data="dataForm.harbor" stripe>
                <el-table-column :label="i18n('business.inquiry.harbor.load_type')" width="80">
                  <template v-slot="scope">
                    <el-text v-if="scope.row.is_load == 1" tag="b" type="primary">
                      {{ $t('business.inquiry.harbor.is_load') }}
                    </el-text>
                    <el-text v-if="scope.row.is_unload == 1" tag="b" type="danger">
                      {{ $t('business.inquiry.harbor.is_unload') }}
                    </el-text>
                  </template>
                </el-table-column>

                <el-table-column prop="harbor_name" :label="i18n('business.inquiry.harbor.harbor_code')" min-width="150">
                </el-table-column>

                <el-table-column prop="second_harbor_name" :label="i18n('business.inquiry.harbor.second_harbor_code')" min-width="150">
                </el-table-column>

                <el-table-column prop="third_harbor_name" :label="i18n('business.inquiry.harbor.third_harbor_code')" min-width="150">
                </el-table-column>
              </el-table>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('business.inquiry.goods.info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-table :data="dataForm.goods" stripe>
                <el-table-column prop="goods_name" :label="i18n('business.inquiry.goods.goods_name')" min-width="240">
                </el-table-column>

                <el-table-column prop="goods_quantity" :label="i18n('business.inquiry.goods.goods_quantity')" width="100">
                </el-table-column>

                <el-table-column prop="goods_weight" :label="i18n('business.inquiry.goods.goods_weight')" min-width="180">
                </el-table-column>

                <el-table-column prop="goods_size" :label="i18n('business.inquiry.goods.goods_size')" min-width="180">
                </el-table-column>

                <el-table-column prop="goods_type" :label="i18n('business.inquiry.goods.goods_type')" width="120">
                </el-table-column>
              </el-table>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('business.inquiry.resource.info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-descriptions border :column="3">
                <el-descriptions-item v-for="(item, index) in dataForm.resource" :key="index" width="200" :label="i18n('business.inquiry.resource.title')" label-align="right">
                  <el-link :href="item.url" :underline="false" type="primary" target="_blank">
                    {{ item.filename }}
                  </el-link>
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-card>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script setup name="business-inquiry-view">
  import { useBase } from "@/hooks/base/useBase"
  import { useForm } from "@/hooks/form/useForm"

  const { router, query, i18n, isAuth } = useBase()

  const model = ref('business/inquiry')

  const dataForm = reactive({
    id: 0,
    order_no: '',
    start_time: '',
    end_time: '',
    description: '',
    remark: '',
    valid_hour: '',
    valid_time: '',
    view_total: '',
    offer_total: '',
    inquiry_status: '',
    create_time: '',
    member: {},
    goods: [],
    harbor: [],
    resource: [],
  })

  const dataRule = reactive({})

  const {
    formRef
  } = useForm(model.value, dataForm)

  const init = (form) => {
    dataForm.id = query.id || 0

    nextTick(() => {
      form.value.resetFields()
      if (dataForm.id) {
        $http({
          url: $http.adornUrl(`/${model.value}/view/${dataForm.id}`),
          method: 'get',
          params: $http.adornParams({}),
        }).then(({ data }) => {
          if (data && data.status === 200) {
            dataForm.id = data.data.id
            dataForm.order_no = data.data.order_no
            dataForm.member = data.data.member
            dataForm.start_time = data.data.start_time
            dataForm.end_time = data.data.end_time
            dataForm.description = data.data.description
            dataForm.remark = data.data.remark
            dataForm.valid_hour = data.data.valid_hour
            dataForm.valid_time = data.data.valid_time
            dataForm.view_total = data.data.view_total
            dataForm.offer_total = data.data.offer_total
            dataForm.inquiry_status = data.data.inquiry_status
            dataForm.create_time = data.data.create_time
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/${model.value}/goods/select`),
              method: 'get',
              params: $http.adornParams({
                'inquiry_id': dataForm.id
              }),
            }).then(({ data }) => {
              if (data && data.data && data.status === 200) {
                dataForm.goods = data.data
              }
            })
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/${model.value}/harbor/select`),
              method: 'get',
              params: $http.adornParams({
                'inquiry_id': dataForm.id
              }),
            }).then(({ data }) => {
              if (data && data.data && data.status === 200) {
                dataForm.harbor = data.data
              }
            })
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/${model.value}/resource/select`),
              method: 'get',
              params: $http.adornParams({
                'inquiry_id': dataForm.id
              }),
            }).then(({ data }) => {
              if (data && data.data && data.status === 200) {
                dataForm.resource = data.data
              }
            })
          }
        })
      }
    })
  }

  onMounted(() => {
    init(formRef)
  })
</script>
